#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int addDigits(int num)
    {
        while (num >= 10)
        {
            int mid = 0;
            while (num)
            {
                mid += num % 10;
                num /= 10;
            }
            num = mid;
        }
        return num;
    }
};